/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package test.shanika;

import static com.googlecode.javacv.cpp.opencv_core.*;
import static com.googlecode.javacv.cpp.opencv_imgproc.*;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
import java.util.Scanner;
import static com.googlecode.javacpp.Loader.sizeof;

/**
 *
 * @author HOME
 */
public class LargeContuor {

    IplImage gray_image, result;
    CvMemStorage mem;
    CvSeq contours = new CvSeq();
    CvSeq ptr = new CvSeq();
    CvSeq largestBlob = new CvSeq();

    public void calCon(IplImage image) {
        gray_image = cvCreateImage(cvGetSize(image), 8, 1);
        cvCvtColor(image, gray_image, CV_BGR2GRAY);
        cvCanny(gray_image, gray_image, 100, 200, 3);
        mem = cvCreateMemStorage(0);


        int a = cvFindContours(gray_image, mem, contours, sizeof(CvContour.class), CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, cvPoint(0, 0));
        result = cvCreateImage(cvGetSize(image), 8, 1);

        for (int i = 0; i < contours.capacity(); i++) {


        }
//    for(int i = 0; i < contours.size(); i++)
//        areas[i] = contourArea(Mat(contours[i]));
//    double max;
//    Point maxPosition;
//    minMaxLoc(Mat(areas),0,&max,0,&maxPosition);
//    drawContours(mask, contours, maxPosition.y, Scalar(1), CV_FILLED);






        cvDrawContours(result, contours, CvScalar.RED, CV_RGB(0, 0, 0), 0, CV_FILLED, 8, cvPoint(0, 0));

    }

    public void calSecondLargest(){
            int secondlargest = 0;
                int largest = 0;
                Scanner input = new Scanner(System.in);
                System.out.println("Enter array values: ");
                int arr[] = new int[5];
                for (int i = 0; i < arr.length; i++) {
                        arr[i] = input.nextInt();
                        if (largest < arr[i]) {
                                secondlargest = largest;
                                largest = arr[i];
                        }
                        if (secondlargest < arr[i] && largest != arr[i])
                                secondlargest = arr[i];
                }
                System.out.println("Second Largest number is: " + secondlargest);
                System.out.println("Largest"+largest);
    }
}
